//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lanf.system.code;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Locale;
import java.util.Map;

public class Freemarker {
    public Freemarker() {
    }

    public static void print(String ftlName, Map<String, Object> root, String ftlPath) throws Exception {
        try {
            Template temp = getTemplate(ftlName, ftlPath);
            temp.process(root, new PrintWriter(System.out));
        } catch (TemplateException var4) {
            throw var4;
        } catch (IOException var5) {
            throw var5;
        }
    }

    public static void printFile(String ftlName, Map<String, Object> root, String outFile, String filePath, String ftlPath) throws Exception {
        if (!filePath.endsWith("/")) {
            filePath = filePath + "/";
        }

        Writer out = null;
        File file = null;

        try {
            file = new File(filePath + outFile);
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }

            System.out.println("=============================");
            System.out.println(file);
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
            Template template = getTemplate(ftlName, ftlPath);
            template.process(root, out);
        } catch (FileNotFoundException var14) {
            throw new RuntimeException("生成代码存放目录所属磁盘不存在");
        } catch (TemplateException var15) {
            throw var15;
        } catch (IOException var16) {
            throw var16;
        } catch (Exception var17) {
            throw var17;
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }

        }

    }

    public static Template getTemplate(String ftlName, String ftlPath) throws Exception {
        try {
            Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
            cfg.setEncoding(Locale.CHINA, "utf-8");
            cfg.setDirectoryForTemplateLoading(new File(ftlPath));
            Template temp = cfg.getTemplate(ftlName);
            return temp;
        } catch (IOException var4) {
            throw var4;
        }
    }
}
